//
//  RecordTableViewCell.m
//  LotteryProject
//
//  Created by 阳光 on 17/7/9.
//  Copyright © 2017年 阳光. All rights reserved.
//

#import "RecordTableViewCell.h"

@interface RecordTableViewCell ()

// 图片
@property(nonatomic,strong)UIImageView *imageUrl;

// 名字
@property(nonatomic,strong)UILabel *nameLabel;

// 金额
@property(nonatomic,strong)UILabel *moneyLabel;

// 状态
@property(nonatomic,strong)UILabel *stateLabel;

// 时间
@property(nonatomic,strong)UILabel *timeLabel;

// 箭头
@property(nonatomic,strong)UIImageView *arrowIcon;

@end

@implementation RecordTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.arrowIcon.hidden=NO;

        self.nameLabel.font=FontNumber(18);

        self.moneyLabel.font=FontNumber(16);

        self.stateLabel.font=FontNumber(16);

        self.timeLabel.font=FontNumber(16);

        self.backgroundColor=WhiteColor;
    }
    return self;
}

-(UIImageView *)imageUrl
{
    if (!_imageUrl) {
        _imageUrl=[UIImageView new];
        _imageUrl.backgroundColor=MainColor;
        [self.contentView addSubview:self.imageUrl];
        ViewBorderRadius(_imageUrl,kmargin*5/2,1,ClearColor);
        [_imageUrl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.size.mas_equalTo(CGSizeMake(kmargin*5,kmargin*5));
            make.centerY.mas_equalTo(0);
        }];
    }
    return _imageUrl;
}


// nameLabel
- (UILabel *)nameLabel
{

    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"11选5" font:FontNumber(18) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.imageUrl.mas_right).offset(kmargin*3/2);
            make.top.mas_equalTo(self.imageUrl.mas_top);
        }];
    }
    return _nameLabel;
}

// moneyLabel
- (UILabel *)moneyLabel
{
    if (!_moneyLabel) {
        _moneyLabel=[self getLabelWithText:@"金额:2元" font:FontNumber(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_moneyLabel];
        [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(kmargin);
            make.bottom.mas_equalTo(self.imageUrl.mas_bottom);
            make.left.mas_equalTo(self.nameLabel.mas_left);
            make.width.mas_equalTo(APPW/4);
        }];
    }
    return _moneyLabel;
}

- (UILabel *)stateLabel
{
    if (!_stateLabel) {
        _stateLabel=[self getLabelWithText:@"进行中" font:FontNumber(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_stateLabel];
        [_stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nameLabel.mas_top);
            make.right.mas_equalTo(self.arrowIcon.mas_left).offset(-kmargin);
        }];
    }
    return _stateLabel;
}

- (UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel=[self getLabelWithText:@"2016.09:12 16.14:48" font:FontNumber(16) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.moneyLabel.mas_top);
            make.right.mas_equalTo(self.arrowIcon.mas_left).offset(-kmargin);
            make.left.mas_equalTo(APPW/2);
        }];
    }
    return _timeLabel;
}


// arrowIcon
-(UIImageView *)arrowIcon
{
    if (!_arrowIcon) {
        _arrowIcon=[UIImageView new];
        [self.contentView addSubview:_arrowIcon];
        _arrowIcon.image=[UIImage imageNamed:@"next_arrow"];
        [_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin*2);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kmargin,kmargin*2));
        }];
    }
    return _arrowIcon;
}

@end
